﻿@using KPIS.GERP.SERVICE.Model
@using KPIS.GERP.MVC.Classes
@model KPIS.GERP.SERVICE.Model.hrm_ps_commands

@{
    ViewBag.Title = "คำสั่งให้ออกราชการ";
}

<div id="pnlHeader" style="margin-left:100px; margin-bottom:30px; width:700px;">
<h2><span class="red">แก้ไข</span> คำสั่งให้ออกราชการ</h2>

@using (Html.BeginForm()) {
    @* @Html.AntiForgeryToken() *@
    @Html.ValidationSummary(true)

    <h4 class="header">แบบฟอร์มคำสั่งให้ออกราชการ</h4>

    <div class="detail">
        @Html.HiddenFor(model => model.cmd_seq)
        
        
        <table class="info">
            <tr>
                <td class="editor-label">

                </td>
                <td class="editor-field">
                    @Html.RadioButtonFor(model => model.cmd_flag, "1") คำสั่งหน่วยงาน
                    @Html.RadioButtonFor(model => model.cmd_flag, "2") คำสั่งภายใน
                    @Html.RadioButtonFor(model => model.cmd_flag, "3") คำสั่งกระทรวง
                    @Html.ValidationMessageFor(model => model.cmd_flag)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.record_status)
                </td>
                <td class="editor-field">
                    @Common.GetRecordStatusName(Model.record_status)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.cmd_type_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.cmd_type_seq)
                        //.Name("ddlCmdType")
                        .BindTo(new SelectList(new GERPContext().hrm_ps_command_types.Where(m => m.cmd_type_seq != 1700 && (m.cmd_group_seq  == 6) ).ToList(), "cmd_type_seq", "cmd_type_name"))
                        //.SelectedIndex(Model != null ? (Model.cmd_type_seq != null ? Model.cmd_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                    )
                    @Html.ValidationMessageFor(model => model.cmd_type_seq)
                </td>
            </tr>

            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.cmd_name)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.cmd_name)
                    @Html.ValidationMessageFor(model => model.cmd_name)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.cmd_ref_no)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.cmd_ref_no)
                    @Html.ValidationMessageFor(model => model.cmd_ref_no)
                </td>
            </tr>

            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.cmd_descr)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.cmd_descr)
                    @Html.ValidationMessageFor(model => model.cmd_descr)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.emp_type_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.emp_type_seq)
                        .BindTo(new SelectList(new GERPContext().hrm_ps_employee_types.ToList(), "emp_type_seq", "emp_type_name"))
                        //.SelectedIndex(Model != null ? (Model.emp_type_seq != null ? Model.emp_type_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                    )
                    @Html.ValidationMessageFor(model => model.emp_type_seq)
                </td>
            </tr>

            @*<tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.penalty_seq)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.penalty_seq)
                        //.Name("ddlPenalty")
                        .BindTo(new SelectList(new GERPContext().hrm_dc_penalty.ToList(), "pen_seq", "pen_name"))
                        //.SelectedIndex(Model != null ? (Model.penalty_seq != null ? Model.penalty_seq.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(events => events.OnChange("ddlPenaltyChange").OnLoad("ddlPenaltyChange"))
                    )
                    @Html.ValidationMessageFor(model => model.penalty_seq)
                </td>
            </tr>*@
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.remarks)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.remarks)
                    @Html.ValidationMessageFor(model => model.remarks)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <h3>หัวรายงาน</h3>
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.cmd_rpt_date)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.cmd_rpt_date)
                    @Html.ValidationMessageFor(model => model.cmd_rpt_date)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.rpt_header)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.rpt_header)
                    @Html.ValidationMessageFor(model => model.rpt_header)
                </td>
            </tr>
        </table>
        <br />
        
    <p id="pnlCommand1">
        <input type="submit" value="บันทึก" />&nbsp;&nbsp;
        @Html.ActionLink("กลับไปหน้าแสดงรายการทั้งหมด", "Index")
        @if(Model.record_status != "A")
        {
            @Html.Raw("&nbsp;&nbsp;|&nbsp;&nbsp;")
            @Html.ActionLink("กลับไปหน้าแสดงรายละเอียด", "Details", new { id = Model.cmd_seq })
        }
    </p>
        <hr />
        <h3><a id="lnkAddDetail" title="คลิกเพื่อเพิ่มรายชื่อบุคลากรในคำสั่ง"><img src="~/Images/Icons/add.png" height="14" /> เพิ่มรายชื่อในคำสั่ง</a></h3>

        @if (Model != null)
        {
            <table class="tablesorter" style="width:660px;">
                <thead>
                    <tr>
                        <th>
                            @Html.DisplayNameFor(model => model.hrm_ps_command_dtls.hrm_ps_employees.full_name)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.hrm_ps_command_dtls.start_date)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.hrm_ps_command_dtls.end_date)
                        </th>
                        <th>

                        </th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var item in Model.col_hrm_ps_command_dtls)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.hrm_ps_employees.full_name)
                        </td>
                        <td>
                            @(item.start_date.HasValue ? item.start_date.Value.ToLongDateString() : "")
                        </td>
                        <td>
                            @(item.end_date.HasValue ? item.end_date.Value.ToLongDateString() : "")
                        </td>
                        <td>
                            @if(Model.record_status != "A")
                            {
                            <a id="lnkEditDetail@(item.cmd_dtls_seq)" title="คลิกเพื่อแก้ไขรายชื่อบุคลากรในคำสั่ง">แก้ไข</a>@Html.Raw("&nbsp;&nbsp;|&nbsp;&nbsp;")
                            @Html.ActionLink("ลบ", "DetailDelete", new { id = item.cmd_dtls_seq, model = item })
                            }
                        </td>
                    </tr>
                }
                </tbody>

            </table>
        }
        
    </div>
}
</div>

<div style="padding-left:100px; margin-bottom:30px;width:550px;" >
    <div id="pnlDetailInfo" hidden>
        @{Html.RenderPartial("../CommandDismiss/CreateDetail", Model.CreateDetail());}
        </div>
    <div id="pnlEditDetailInfo" hidden>
        @{Html.RenderPartial("../CommandDismiss/EditDetail", Model.hrm_ps_command_dtls);}
    </div>
</div>

@section Scripts {
    <script type="text/javascript" >
        jQuery(function ($) {
            $("input#approved_type").change(function () {
                $("#divApproverInternal").toggle(this.value == "1");
                $("#divApproverExternal").toggle(this.value == "2");
            });
            $("input#approved_type:checked").change();
        });

        function ddlPenaltyChange(e) {
            var comboBox = $("#penalty_seq").data("tComboBox");
            $("[id^='lblCmdTypeName']").text('โทษ>' + comboBox.text());
        }

        jQuery(function ($) {
            $("#lnkAddDetail").click(function () {
                //$("#lnkAddDetail").hide();
                $("#pnlHeader").hide("slide", { direction: "left" }, 300, function () {
                    $("#pnlDetailInfo").show("slide", { direction: "right" }, 300)
                });
            });

            //$("#lnkAddDetail").show();
            $("#pnlHeader").show("slide", { direction: "left" }, 300);
            $("#pnlDetailInfo").hide();
            $("#pnlEditDetailInfo").hide();

            $("[id^=lnkEditDetail]").click(function (event) {
                //var id = $("#CmdDtlsSeq").val();
                $.getJSON('@Url.Action("GetDetail", "CommandDismiss")', { 'id': event.target.id.replace("lnkEditDetail", "") }, function (data) {


                    var cmd_seq = $("#EditInfo").find("#cmd_seq");
                    var cmd_dtls_seq = $("#EditInfo").find("#cmd_dtls_seq");
                    var emp_seq = $("#EditInfo").find("#emp_seq");
                    var start_date = $("#EditInfo").find("#start_date");
                    var end_date = $("#EditInfo").find("#end_date");
                    var remarks = $("#EditInfo").find("#remarks");
                    var rpt_remarks = $("#EditInfo").find("#rpt_remarks");

                    cmd_seq.val(data.cmd_seq);
                    cmd_dtls_seq.val(data.cmd_dtls_seq);
                    emp_seq.val(data.emp_seq);
                    start_date.val(data.start_date);
                    end_date.val(data.end_date);
                    remarks.val(data.remarks);
                    rpt_remarks.val(data.rpt_remarks);

                });
                //$("#lnkAddDetail").hide();
                $("#pnlHeader").hide("slide", { direction: "left" }, 300, function () {
                    $("#pnlEditDetailInfo").show("slide", { direction: "right" }, 300)
                });
                //$("#pnlDetailInfo").hide({ speed: 500 })
            });

            $("#lnkCancel").click(function () {

                $("#pnlDetailInfo").hide("slide", { direction: "right" }, 300, function () {
                    $("#pnlHeader").show("slide", { direction: "left" }, 300)
                });
                //$("#lnkAddDetail").show();
            });

            $("#lnkEditCancel").click(function () {

                $("#pnlEditDetailInfo").hide("slide", { direction: "right" }, 300, function () {
                    $("#pnlHeader").show("slide", { direction: "left" }, 300)
                });
                //$("#lnkAddDetail").show();
            });
        });

        jQuery(function ($) {
            $(".datepicker").datepicker({
                showOn: "focus",
                buttonImage: "../../Images/Icons/calendar.png",
                buttonImageOnly: true,
                dateFormat: "dd/mm/yy",
                isBE: true
            });
        });

        jQuery(function ($) {
            $("table.tablesorter").tablesorter({ widthFixed: true, sortList: [[0, 0]], widgets: ["zebra", "filter"] });
                //.tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
        });
    </script>
}
